package systems;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.Image;

import com.artemis.Entity;
import com.artemis.EntityProcessingSystem;
import com.artemis.ComponentMapper;

import components.Position;
import components.Sprite;

public class RenderingSystem extends EntityProcessingSystem
{
	private ComponentMapper<Position> pos;
	private ComponentMapper<Sprite> sprite;
	
	@SuppressWarnings("unchecked")
	public RenderingSystem()
	{
		super(Sprite.class);
	}
	
	public void initialize()
	{
		pos = new ComponentMapper<Position>(Position.class, world);
		sprite = new ComponentMapper<Sprite>(Sprite.class, world);
	}
	
	public void process(Entity e)
	{
		//Update rotation of image
		if(sprite.get(e).getImage().getRotation() != pos.get(e).getTheta())
		{
			sprite.get(e).getImage().setRotation(pos.get(e).getTheta());
		}
		
		sprite.get(e).getImage().drawCentered(pos.get(e).getX(), pos.get(e).getY());
	}
}
